package main

import "fmt"

func main() {
	digits := []int{8, 9, 9, 9}
	fmt.Println(plusOne(digits))
}

//#link: https://leetcode-cn.com/problems/plus-one/
func plusOne(digits []int) []int {
	ans := make([]int, len(digits))
	isCarry := 1
	for i := len(digits) - 1; i >= 0; i-- {
		sum := isCarry + digits[i]
		ans[i] = sum % 10
		isCarry = sum / 10
	}
	if isCarry != 0 {
		ansCopy := []int{isCarry}
		ansCopy = append(ansCopy, ans...)
		ans = ansCopy
	}
	return ans
}
